package dao

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"log"
	"time"
)

var GLOBAL_DB *gorm.DB

func init() {
	db, err := gorm.Open(mysql.New(mysql.Config{
		DSN: "root:root@tcp(120.48.83.21:3306)/lysb?charset=utf8mb4&parseTime=True&loc=Local",
	}), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})

	if err != nil {
		log.Fatal(err)
	}

	sqlDB, _ := db.DB()
	sqlDB.SetMaxIdleConns(10)
	sqlDB.SetMaxOpenConns(100)
	sqlDB.SetConnMaxIdleTime(time.Hour)
	sqlDB.SetConnMaxLifetime(time.Hour)
	GLOBAL_DB = db
}
